#ifndef CODEEDITOR_H
#define CODEEDITOR_H
#include <Qsci/qsciscintilla.h>
#include <QKeyEvent>
#include <QHash>
#include <QListView>

class ProjectManager;

class CodeEditor : public QsciScintilla
{
    Q_OBJECT
private:
    ProjectManager * m_projectManager;
    int m_wordOffset;
    bool m_forwardSearchDirection;
    int m_hyperlinkedRangeStart;
    int m_hyperlinkedRangeLength;
    QHash<QString, QString> m_navigationListContent;
    QListView * m_completionList;
public:
    explicit CodeEditor(QWidget *parent = 0);
    void keyPressEvent(QKeyEvent *e);
    void keyReleaseEvent(QKeyEvent *e);
    void setProjectManager(ProjectManager * aManager);
    int getWordOffset();
    void findAndScrollToWord(QString aWord);
    void findNextMatch(QString aWord);
    void findPreviousMatch(QString aWord);
    void replaceAll(QString aOldText, QString aNewText);
    //void replaceInSelection(QString aOldText, QString aNewText);
    void goToOffset(int aOffset);
    void parseGlobalLink(QString aGlobalLink, QStringList &aComponents);
    QString getGlobalLinkByFormattedLink(QString aFormattedLink);
    void scrollContentsBy(int dx, int dy);
    void indentSelection();
    void unindentSelection();
    int getCursorOffset();
    void initFromSettings();
protected:
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent ( QMouseEvent * event );
signals:
    void linkClicked(QString aLink);
    void scrolled(int aOffset);
    void searchRequested();
    void hideSearch();
};

#endif // CODEEDITOR_H
